//
//  HMRefreshView.swift
//  微博新浪
//
//  Created by hezerong on 16/6/12.
//  Copyright © 2016年 Rocky. All rights reserved.
//

import UIKit
import HMRefresh

class HMPulldownView: UIView ,HMRefreshViewDelegate{

    
    //背景图片
    var pullDownBackGroundImage: UIImageView?
    /// 下拉提示图像
    var pulldownIcon: UIImageView?
    /// 刷新指示器
    var refreshIndicator: UIActivityIndicatorView?
    /// 提示标签
    var tipLabel: UILabel?
    /// 刷新时间标签
    var timeLabel: UILabel?
    

   
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}


extension HMPulldownView{

    func setUpUI(){
        
        //设置数据
         pullDownBackGroundImage = UIImageView(imageName: "refreshbg")
         pulldownIcon = UIImageView(imageName: "pull_refresh")
        refreshIndicator = UIActivityIndicatorView()
        tipLabel = UILabel(text: "下拉刷新",  fontSize: 10 )
        timeLabel = UILabel(text: "上次刷新",  fontSize: 10)
        
        //添加子控件
         self.addSubview(pullDownBackGroundImage!)
         self.addSubview(pulldownIcon!)
         self.addSubview(refreshIndicator!)
         self.addSubview(tipLabel!)
         self.addSubview(timeLabel!)
        
        //布局
        pullDownBackGroundImage?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.right.left.bottom.equalTo(self)
            make.height.equalTo(400)
        })
        
        pulldownIcon?.snp_makeConstraints(closure: { (make) -> Void in
            
            make.left.equalTo(self).offset(90)
            make.centerY.equalTo(self)
            
        })
        
        refreshIndicator?.snp_makeConstraints(closure: { (make) -> Void in
            make.left.equalTo(self).offset(120)
            make.centerY.equalTo(-11)
        })
        
        tipLabel?.snp_makeConstraints(closure: { (make) -> Void in
            make.left.equalTo(self).offset(120)
            make.centerY.equalTo(-22)
        })
        
        timeLabel?.snp_makeConstraints(closure: { (make) -> Void in
            make.left.equalTo(self).offset(120)
            make.centerY.equalTo(-1)
        })

    
    
    }
}